package com.sc.admin.base.controller;


import com.sc.admin.base.service.ISystemService;
import com.sc.common.response.Response;
import com.sc.core.make.dto.MakeInfoDTO;
import com.sc.core.make.vo.TableColumn;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("admin-base/system")
@AllArgsConstructor
@Log4j2
public class SystemController {

    private final ISystemService systemService;

    @GetMapping("make-curd")
    public String index(Model model) {

        model.addAttribute("tableList", systemService.getTableList());
        model.addAttribute("packageList", systemService.getAdminPackageList());
        model.addAttribute("moduleList", systemService.getAdminModuleList());

        return "base/system/make-curd";
    }

    @GetMapping("get-table-column")
    @ResponseBody
    public Response<List<TableColumn>> getTableColumn(@Param("tableName") String tableName) {

        List<TableColumn> tableColumn = systemService.getTableColumn(tableName);

        return Response.success(tableColumn);
    }

    @PostMapping("make-curd")
    @ResponseBody
    public Response<List<String>> makeCurd(@RequestBody MakeInfoDTO makeInfo){
        List<String> message = systemService.makeCurd(makeInfo);

        return Response.success(message);
    }
}
